package wei.xinya.hbase.controller;

import org.springframework.web.bind.annotation.*;
import wei.xinya.hbase.config.HBaseUtils;
import wei.xinya.hbase.dto.GetDataDTO;
import wei.xinya.hbase.dto.PutDataDTO;

import javax.annotation.Resource;
import java.util.Arrays;

@RestController
@RequestMapping("/hbase")
public class HBaseController {
    @Resource
    private HBaseUtils hBaseUtils;

    @PostMapping("/createTable")
    public Object createTable(@RequestParam String tableName, @RequestParam String columnFamily) {
        return hBaseUtils.createTable(tableName, Arrays.asList(columnFamily.split(",")));
    }

    @PostMapping("/dropTable")
    public Object dropTable(@RequestParam String tableName) {
        return hBaseUtils.dropTable(tableName);
    }

    @PostMapping("/putData")
    public Object putData(@RequestBody PutDataDTO putDataDTO) {
        return hBaseUtils.putData(putDataDTO);
    }

    @PostMapping("/getData")
    public Object getData(@RequestBody GetDataDTO getDataDTO) {
        return hBaseUtils.getData(getDataDTO.getTableName());
    }

}
